@extends('admin.index')
@section('content')
    <div class="layuibodycont">
        <div class="clearfix">
            <p class="capitalnav capitalnav02">订单列表</p>
            <div class="orderform">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">订单号：</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input order_number" name="order_number" value="{{!empty($order_number)?$order_number:''}}" placeholder="请输入订单号">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单状态：</label>
                            <div class="layui-input-inline">
                                <select class="order_status" name="order_status" lay-filter="aihao">
                                    <option value="0" <?php echo ($order_status == 0) ?'selected':''?> >请选择</option>
                                    <option value="1" <?php echo ($order_status == 1) ?'selected':''?>>未支付</option>
                                    <option value="2" <?php echo ($order_status == 2) ?'selected':''?>>已支付</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="margin-bottom:0px;">
                        <div class="layui-inline">
                            <label class="layui-form-label">按时间：</label>
                            <div class="layui-input-inline">
                                <input class="layui-input ktime" name="ktime" value="{{(isset($times['k']) && !empty($times['k']))?date('Y-m-d H:i:s',$times['k']):''}}" placeholder="开始日" id="LAY_demorange_s">
                            </div>
                            <div class="layui-input-inline">
                                <input class="layui-input gtime" name="gtime" value="{{(isset($times['e']) && !empty($times['e']))?date('Y-m-d H:i:s',$times['e']):''}}" placeholder="截止日" id="LAY_demorange_e">
                            </div>
                            <button class="layui-btn">搜索</button>
                        </div>
                        <span class="layui-btn doexport" style="float:right;margin-right: 9px">导出订单</span>
                    </div>
                </form>
            </div>
            <div class="streambox">
                <table class="layui-table streamtable" lay-skin="line">
                    <thead>
                    <tr>
                        <th>订单号</th>
                        <th>商品</th>
                        <th>订单状态</th>
                        <th>下单时间</th>
                        <th>收件人姓名</th>
                        <th>收件人联系方式</th>
                        <th>收件人地址</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        @if(!empty($order))
                            @foreach($order as $k=>$v)
                                <tr>
                                    <td><p class="wordpro">{{$v['order_no']}}</p></td>
{{--
                                    <td><p class="wordpro"><img src="{{isset($v['customer']['headimgurl'])?$v['customer']['headimgurl']:''}}" class="tdcustomerhead"><span class="tdcustomername">{{isset($v['customer']['nickname'])?$v['customer']['nickname']:''}}</span></p></td>
--}}
                                    <td>
                                        <p class="wordpro">
                                            @if($v['type'] == 1)
                                                黄纸板
                                            @elseif($v['type'] == 2)
                                                易拉罐，饮料瓶
                                            @else
                                                白废纸
                                            @endif
                                        </p>
                                    </td>
                                    <td>
                                        <p class="wordpro">
                                            @if($v['status'] == 1)
                                                待回收
                                            @elseif($v['status'] == 2)
                                                已回收
                                            @endif
                                        </p>
                                    </td>
                                    <td><p class="wordpro">{{$v['created_at']}}</p></td>
                                    {{--<td>
                                        @if($v['order_status'] == 2)
                                            <span class="layui-btn agree_ak" numb="{{$v['order_number']}}">退款</span>
                                            --}}{{--<span class="layui-btn refuse_ak"  numb="{{$v['order_number']}}">拒绝</span>--}}{{--
                                        @endif
                                    </td>--}}
                                    <td><p class="wordpro">{{$v['username']}}</p></td>
                                    <td><p class="wordpro">{{$v['phone']}}</p></td>
                                    <td><p class="wordpro">{{$v['address']}}</p></td>
                                    <td><p class="wordpro"></p></td>
                                </tr>
                            @endforeach
                        @endif
                    </tbody>
                </table>

                <div class="paginationbox">
                    {{ $order->appends(['order_number'=>$order_number,'order_status'=>$order_status,'paytype'=>$paytype,'ktime'=>((isset($times['k']) && !empty($times['k']))?date('Y-m-d H:i:s',$times['k']):''),'gtime'=>((isset($times['e']) && !empty($times['e']))?date('Y-m-d H:i:s',$times['e']):'')])->render() }}
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //时间选择器
            laydate.render({
                elem: '#LAY_demorange_s'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#LAY_demorange_e'
                ,type: 'datetime'
            });
        });

        // 导出
        $(document).on('click', '.doexport', function(){
            var channel_account = $('.channel_account').val();
            var order_number = $('.order_number').val();
            var order_status = $('.order_status option:selected').val();
            var ktime = $('input[name=ktime]').val();
            var gtime = $('input[name=gtime]').val();
            location.href = '/merchantadm/order/exportorder?channel_account='+channel_account+'&order_number='+order_number+'&order_status='+order_status+'&ktime='+ktime+'&gtime='+gtime;
        });



        // 同意退款
        $(document).on('click', '.agree_ak', function(){
            var order_number = $(this).attr('numb');
            if (!order_number) {
                layer.msg('缺少参数', {icon: 5, time:1000});
                return false;
            }
            layer.open({
                type: 1
                ,title: false //不显示标题栏
                ,closeBtn: false
                ,area: ['400px', '180']
                ,shade: 0.8
                ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                ,btn: ['确认', '取消']
                ,moveType: 1 //拖拽模式，0或者1
                ,content: $('#layer_maxstock')
                ,success: function(layero){
                },yes: function(index, layero){
                    var remarks = $('input[name=remarks]').val();
                    //var contact = $('input[name=contact]').val();
                    var password = $('input[name=password]').val();
                    if (!remarks) {
                        layer.msg('还未填写备注', {icon: 5});
                        return false;
                    }
                    $.ajax({
                        url : '/merchantadm/order/refunds',
                        type : 'post',
                        data : {order_num:order_number,remarks:remarks,password:password},
                        dataType : 'json',
                        success : function(msg){
                            console.log(msg);
                            if (msg.success == 1) {
                                layer.msg(msg.data, {icon: 6,time:1000});
                                setTimeout(function(){
                                    window.location.reload();
                                }, 1000);
                            } else {
                                layer.msg(msg.error, {icon: 5});
                                return false;
                            }
                        }
                    });
                },btn2:function(index, layero){
                    layer.closeAll();
                }
            });

        });
    </script>
@endsection
{{--弹框的内容--}}
@section('alertbox')
    <div id="layer_maxstock" style="display: none;">
        <div class="goodchatbox">
            <form class="layui-form" id="form_data"  enctype="multipart/form-data">
                <ul class="addlayerul">
                    <li>
                        <div class="addlayerli">
                            <span class="addlayerlipan">备注：</span>
                            <div class="addlayerlidiv">
                                <input type="text" name="remarks" class="addlayerliput" placeholder="" />
                            </div>
                        </div>
                    </li>
                    {{--<li>
                        <div class="addlayerli">
                            <span class="addlayerlipan">联系方式：</span>
                            <div class="addlayerlidiv">
                                <input type="text" name="contact" class="addlayerliput" placeholder="" />
                            </div>
                        </div>
                    </li>--}}
                    <li>
                        <div class="addlayerli">
                            <span class="addlayerlipan">密码：</span>
                            <div class="addlayerlidiv">
                                <input type="password" name="password" class="addlayerliput" placeholder="" />
                            </div>
                        </div>
                    </li>
                </ul>
            </form>
        </div>
    </div>
@endsection